#define _CRT_SECURE_NO_WARNINGS 1

int romanToInt(char* s) {
    int total = 0;
    int sz = 0;
    while (s[sz] != '\0')
    {
        if (s[sz] == 'I' && (s[sz + 1] == 'V' || s[sz + 1] == 'X'))
        {
            total += -1 + ((s[sz + 1] == 'V') ? 5 : 10);
            sz += 2;
            continue;
        }
        if (s[sz] == 'X' && (s[sz + 1] == 'L' || s[sz + 1] == 'C'))
        {
            total += -10 + ((s[sz + 1] == 'L') ? 50 : 100);
            sz += 2;
            continue;
        }
        if (s[sz] == 'C' && (s[sz + 1] == 'D' || s[sz + 1] == 'M'))
        {
            total += -100 + ((s[sz + 1] == 'D') ? 500 : 1000);
            sz += 2;
            continue;
        }

        switch (s[sz])
        {
        case 'I':
            total += 1;
            break;
        case 'V':
            total += 5;
            break;
        case 'X':
            total += 10;
            break;
        case 'L':
            total += 50;
            break;
        case 'C':
            total += 100;
            break;
        case 'D':
            total += 500;
            break;
        case 'M':
            total += 1000;
            break;
        }
        sz++;
    }

    return total;

}